package form_check

import (
	"errors"
	"gateway/tools/user"

	"strings"
)

func CheckData(json user.UpdateJson) error {
	if json.NewPhone != "" && len(json.NewPhone) != 11 {
		return errors.New("不合法的账号")
	}
	if json.NewPassword1 != json.NewPassword2 {
		return errors.New("两次密码不一致")
	}
	if (json.NewPassword1 != "" && json.NewPassword2 != "") && !strings.ContainsAny(json.NewPassword1, "qwertyuioplkjhgfdsazxcvbnm | QWERTYUIOPLKJHGFDSAZXCVBNM") {
		return errors.New("密码安全难度低")
	}
	//	校验邮箱是否合规
	if json.Email != "" && (!strings.Contains(json.Email, "@qq.com") && !strings.Contains(json.Email, "@163.com") && !strings.Contains(json.Email, "@gmail.com")) {
		return errors.New("不合规的邮箱号")
	}
	return nil
}
